package cn.youyeku.zsxh.Utils;

import android.util.Log;

/**
 * Created by wings on 2017/3/14.
 * <p>
 * 整合了生命周期 关闭生命周期显示 set LOG_LIFE_CYCLE = false;
 * 关闭debug set DEBUG=4; 大于等于debug的函数将会显示
 */

public class LogUtils {


    //关闭debug 设置值为4
    private static int DEBUG = 0;
    private final static int LOG_DEBUG = 0;
    private final static int LOG_INFO = 1;
    private final static int LOG_WARN = 2;
    private final static int LOG_ERROR = 3;

    private final static String LOG_INFO_TAG = "正常";
    private final static String LOG_ERROR_TAG = "错误";
    private final static String LOG_WARN_TAG = "警告";
    private final static String LOG_DEBUG_TAG = "调试";
    private final static String LOG_LIFE_TAG = "生命周期";


    private final static boolean LOG_LIFE_CYCLE = true;
    private final static String LOG_COMMOM_INFO = " 类-->%s  行-->%s 方法名-->%s 输出-->  %s";
    private final static String LOG_LIFE_INFO = " 类-->%s 输出-->%s ";

    public final static void life(String class_name, String message) {
        if (LOG_LIFE_CYCLE) {

            Log.i(LOG_LIFE_TAG,
                    String.format(LOG_LIFE_INFO, class_name, message)
            );
        }
    }

    public final static void e(String message) {
        if (DEBUG <= LOG_ERROR) {
            StackTraceElement stackTrace = new Throwable().getStackTrace()[1];

            Log.e(LOG_ERROR_TAG,
                    String.format(LOG_COMMOM_INFO, stackTrace.getClassName(),
                            stackTrace.getLineNumber(), stackTrace.getMethodName()
                            , message)
            );

        }

    }


    public final static void i(String message) {
        if (DEBUG <= LOG_INFO) {
            StackTraceElement stackTrace = new Throwable().getStackTrace()[1];
            Log.i(LOG_INFO_TAG,
                    String.format(LOG_COMMOM_INFO, stackTrace.getClassName(),
                            stackTrace.getLineNumber(), stackTrace.getMethodName()
                            , message)
            );

        }
    }

    public final static void d(String message) {
        if (DEBUG <= LOG_DEBUG) {
            StackTraceElement stackTrace = new Throwable().getStackTrace()[1];
            Log.d(LOG_DEBUG_TAG,
                    String.format(LOG_COMMOM_INFO, stackTrace.getClassName(),
                            stackTrace.getLineNumber(), stackTrace.getMethodName()
                            , message)

            );
        }
    }

    public final static void w(String message) {
        if (DEBUG <= LOG_WARN) {
            StackTraceElement stackTrace = new Throwable().getStackTrace()[1];
            Log.w(LOG_WARN_TAG,
                    String.format(LOG_COMMOM_INFO, stackTrace.getClassName(),
                            stackTrace.getLineNumber(), stackTrace.getMethodName()
                            , message)
            );
        }
    }
}